package com.junbao.message.infrastructure.dao;

import org.apache.commons.dbutils.QueryRunner;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.junbao.commom.exception.JunBaoException;
import com.junbao.message.infrastructure.repository.TimingTaskDao;
import com.junbao.message.infrastructure.util.JdbcUtils;
/**
 * 定时任务开关信息 实现类
 * @author yyp
 *
 */
public class TimingTaskDaoImpl implements TimingTaskDao {

	private static final Logger LOGGER = LoggerFactory.getLogger(TimingTaskDaoImpl.class);
	
	
	public Integer updateMessageToDeadTaskSwitch(String taskSwitchOne,String taskSwitchTwo) throws Exception {
		try {
			QueryRunner runner = new QueryRunner(JdbcUtils.getDataSource("message"));
			String sql = "UPDATE timing_task_switch SET task_switch=? WHERE task_switch=? and task_id = 1";
			int count = runner.update(sql, taskSwitchOne,taskSwitchTwo);
			return count; 
		} catch (Exception e) {
			LOGGER.error(" 通过任务名称task_name修改任务失败!", e);
			throw new JunBaoException("8888"," 通过任务名称task_name修改任务失败!");
		}
	}
	
	
	public Integer updateMessageToWaitConfirmTaskSwitch(String taskSwitchOne,String taskSwitchTwo) throws Exception {
		try {
			QueryRunner runner = new QueryRunner(JdbcUtils.getDataSource("message"));
			String sql = "UPDATE timing_task_switch SET task_switch=? WHERE task_switch=? and task_id = 2";
			int count = runner.update(sql, taskSwitchOne,taskSwitchTwo);
			return count; 
		} catch (Exception e) {
			LOGGER.error(" 通过任务名称task_name修改任务失败!", e);
			throw new JunBaoException("8888"," 通过任务名称task_name修改任务失败!");
		}
	}

	
	public Integer updateMessageConfirmSwitch(String taskSwitchOne, String taskSwitchTwo) throws Exception {
		try {
			QueryRunner runner = new QueryRunner(JdbcUtils.getDataSource("message"));
			String sql = "UPDATE timing_task_switch SET task_switch=? WHERE task_switch=? and task_id = 3";
			int count = runner.update(sql, taskSwitchOne,taskSwitchTwo);
			return count; 
		} catch (Exception e) {
			LOGGER.error(" 通过任务名称task_name修改任务失败!", e);
			throw new JunBaoException("8888"," 通过任务名称task_name修改任务失败!");
		}
	}

	
	public Integer updateMessageRetryTaskSwitch(String taskSwitchOne, String taskSwitchTwo) throws Exception {
		try {
			QueryRunner runner = new QueryRunner(JdbcUtils.getDataSource("message"));
			String sql = "UPDATE timing_task_switch SET task_switch=? WHERE task_switch=? and task_id = 4";
			int count = runner.update(sql, taskSwitchOne,taskSwitchTwo);
			return count; 
		} catch (Exception e) {
			LOGGER.error(" 通过任务名称task_name修改任务失败!", e);
			throw new JunBaoException("8888"," 通过任务名称task_name修改任务失败!");
		}
	}
	
	
	public Integer updateMessageRemovalSwitch(String taskSwitchOne, String taskSwitchTwo) throws Exception {
		try {
			QueryRunner runner = new QueryRunner(JdbcUtils.getDataSource("message"));
			String sql = "UPDATE timing_task_switch SET task_switch=? WHERE task_switch=? and task_id = 5";
			int count = runner.update(sql, taskSwitchOne,taskSwitchTwo);
			return count; 
		} catch (Exception e) {
			LOGGER.error(" 通过任务名称task_name修改任务失败!", e);
			throw new JunBaoException("8888"," 通过任务名称task_name修改任务失败!");
		}
	}

	@Override
	public Integer messageStatusToWaitConfirmFromConfirmingUpdateSwitch(String taskSwitchOne, String taskSwitchTwo) throws Exception {
		try {
			QueryRunner runner = new QueryRunner(JdbcUtils.getDataSource("message"));
			String sql = "UPDATE timing_task_switch SET task_switch=? WHERE task_switch=? and task_id = 6";
			int count = runner.update(sql, taskSwitchOne,taskSwitchTwo);
			return count; 
		} catch (Exception e) {
			LOGGER.error(" 通过任务名称task_name修改任务失败!", e);
			throw new JunBaoException("8888"," 通过任务名称task_name修改任务失败!");
		}
	}
	
	@Override
	public int messageStatusToWaitSendFromSendingUpdateSwitch(String taskSwitchOne, String taskSwitchTwo) throws Exception {
		try {
			QueryRunner runner = new QueryRunner(JdbcUtils.getDataSource("message"));
			String sql = "UPDATE timing_task_switch SET task_switch=? WHERE task_switch=? and task_id = 7";
			int count = runner.update(sql, taskSwitchOne,taskSwitchTwo);
			return count; 
		} catch (Exception e) {
			LOGGER.error(" 通过任务名称task_name修改任务失败!", e);
			throw new JunBaoException("8888"," 通过任务名称task_name修改任务失败!");
		}
	}
	
}
